<?php
/**
 *file-level documentation
 *@author Name <email@exp.com>
 *27 May 2012
 *@copyright Copyright (c) 2012, Tuncay Bakan
 *@package somePackage
 *
 */
/**
 *shows the home site
 */
class Help_Controller extends Controller{
   /**
     * Holds id of page to be displayed
     * @var integer
     */
    private $iPageID = '';

    /**
     * Language in which to show page
     * @var integer
     */
    private $iLang = '';

    //Declare models to retriev page data and views to display the data

    /**
     * Reference to view of content section
     * @var object
     */
    private $oContentView;

    /**
     * Reference to model that retrieves page data from db
     * @var object
     */
    private $oContentModel;
    /**
     * Sets the template of the help page
     * @var string
     */
    private $sTemplate ='contentPage';
    /**
     * Reference to model that retrieves page navigation elements from db
     * @var object
     */
    private $oNavigationModel;

    /**
     * Reference to view of navigation section
     * @var object
     */
    private $oNavigationView;

    /**
     * Reference to view of left navigation section in cms, its shows the entire pagestructure
     * @var object
     */
    private $oLeftNavigationView;
    /**
     * Controller which was used when the help button was pressed
     * @var string
     */
    private $sController;
    
    
    public function __construct(){
          //Gets Viewmanger reference from parent constructor
        parent::__construct();
//Loads models and views
        $this->oContentModel = Loader::loadModel('help');
        $this->oNavigationModel = Loader::loadModel('navigation');
        $this->oContentView = $this->oViewmanager->getView('contentPage');
        $this->oNavigationView = $this->oViewmanager->getView($GLOBALS['NAVIGATIONTEMP']);
        $this->oLeftNavigationView = $this->oViewmanager->getView('leftnavigation');
//Checks language set in Cookie, take default language specified in config if not set
        if (isset($_COOKIE['language'])){
            $this->iLang = intval($_COOKIE['language']);
        }else{
            $this->iLang = "1";
        }


    }
/**
 * Checks GET-Parameters forwarded from Router::route
 * @param array arguements to check 
 */
    public function checkArgs($aArgs){

        
        if(empty($aArgs) || empty($aArgs['controllerHelp']) || $aArgs['controllerHelp'] == "help" ){
            $this->sController= "index";
        }else{
            $this->sController= $aArgs['controllerHelp'];
        } 
    }

    public function execute($aArgs){
        $this->checkArgs($aArgs);
        
        $this->oContentView->assign('content', $this->oContentModel->getHelpContent($this->sController, $this->iLang));
        //Checks if mobile device is used
        if($GLOBALS['ISMOBILE']==1){
            $this->oNavigationView->assign('navigation', $this->oNavigationModel->getPageStructure($this->mNavigationRoot,$this->iLang));
        }else{
            $this->oNavigationView->assign('navigation', $this->oNavigationModel->getPageStructure('NULL',$this->iLang));
        }
        $this->oLeftNavigationView->assign('productsANDcategories', $this->oNavigationModel->getProdCat('',$this->iLang, 'product'));
        //Inserts data in the correct sections of the website layout
        $this->oViewmanager->setSection('Title', $this->oContentModel->getHelpTitle($this->sController, $this->iLang));
        $this->oViewmanager->setSection('Content', $this->oContentView->display());
        $this->oViewmanager->setSection('LeftNavigationTitle', $this->oNavigationModel->getLeftNavigationTitle($this->iLang));
        $this->oViewmanager->setSection('LeftNavigation', $this->oLeftNavigationView->display());
        $this->oViewmanager->setSection('Navigation', $this->oNavigationView->display());
       
    }

/**
 * Ajax function to load the help dynamically
 */
    public function getHelp(){
        $this->checkArgs($_GET);
        $this->oContentView->assign('title', $this->oContentModel->getHelpTitle($this->sController,$this->iLang));
        $this->oContentView->assign('content', $this->oContentModel->getHelpContent($this->sController, $this->iLang));
        
        echo $this->oContentView->display();
    }
}
?>


